package com.ruoyi.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Product;
import com.ruoyi.system.service.IProductService;

/**
 * 备品Controller
 * 
 * @author winner pan
 * @date 2022-05-13
 */
@RestController
@RequestMapping("/system/product")
public class ProductController extends BaseController {
	@Autowired
	private IProductService productService;

	/**
	 * 查询备品列表
	 */
	@PreAuthorize("@ss.hasPermi('labbase:product:query')")
	@GetMapping("/list")
	public TableDataInfo list(Product product) {
		startPage();
		List<Product> list = productService.selectProductList(product);
		return getDataTable(list);
	}

	/**
	 * 导出备品列表
	 */
	/*@PreAuthorize("@ss.hasPermi('system:product:export')")
	@Log(title = "备品", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(Product product) {
		List<Product> list = productService.selectProductList(product);
		ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
		return util.exportExcel(list, "product");
	}*/

	/**
	 * 获取备品详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labbase:product:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(productService.selectProductById(id));
	}

	/**
	 * 新增备品
	 */
	@PreAuthorize("@ss.hasPermi('system:product:add')")
	@Log(title = "备品", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody Product product) {
		return toAjax(productService.insertProduct(product));
	}

	/**
	 * 修改备品
	 */
	@PreAuthorize("@ss.hasPermi('system:product:edit')")
	@Log(title = "备品", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody Product product) {
		return toAjax(productService.updateProduct(product));
	}

	/**
	 * 删除备品
	 */
	@PreAuthorize("@ss.hasPermi('system:product:remove')")
	@Log(title = "备品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(productService.deleteProductByIds(ids));
	}
}